package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;

import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("查询护理等级列表")
    public ResponseResult<List<NursingLevelVo>> listAll(){
        List<NursingLevelVo> nursingLevels = nursingLevelService.listAll();
        return success(nursingLevels);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult levelAdd(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.levelAdd(nursingLevelDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("护理等级分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> levelSearchPage(
                                          @ApiParam(value = "当前页码") @RequestParam(defaultValue = "1",required = false)Integer pageNum,
                                          @ApiParam(value = "每页显示条数") @RequestParam(defaultValue = "10",required = false)Integer pageSize,
                                          @ApiParam(value = "护理项目名称") String name,
                                          @ApiParam(value = "状态")Integer status){
        PageResponse<NursingLevelVo> response = nursingLevelService.levelSearchPage(pageNum, pageSize, name, status);
        return success(response);
    }

    @GetMapping("/{id}")
    @ApiOperation("护理等级根据id查询")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Integer id){
        NursingLevelVo vo = nursingLevelService.getById(id);
        return success(vo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult updateLevel(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除护理等级")
    public ResponseResult delete(@PathVariable Integer id){
        nursingLevelService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("设置启用与禁用护理等级")
    public ResponseResult setStatus(@PathVariable Integer id,
                                    @PathVariable Integer status){
        nursingLevelService.setStatus(id,status);
        return success();
    }
}
